home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / kernel.ph < prev    next >
Text File  |  1994-04-25  |  16KB  |  465 lines

  1. /*****************************************************************************
  2.   FILE           : kernel.ph
  3.   SHORTNAME      : kernel.ph
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS Kernel Function Prototypes
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Niels Mache
  10.   DATE           : 20.02.90
  11.  
  12.   CHANGED BY     : Michael Vogt, Guenter Mamier
  13.   IDENTIFICATION : @(#)kernel.ph    1.14 4/8/94
  14.   SCCS VERSION   : 1.14
  15.   LAST CHANGE    : 4/8/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20. #ifndef _KENREL_DEFINED_
  21. #define  _KENREL_DEFINED_
  22.  
  23. /* begin global definition section */
  24.  
  25. /*#################################################
  26.  
  27. GROUP:  Parallel kernel functions
  28.  
  29. #################################################*/
  30.  
  31. #ifdef  MASPAR_KERNEL
  32. /*  Connects and Disconnects the MasPar.
  33.     The mode switches are:  MASPAR_CONNECT and MASPAR_DISCONNECT. */
  34. krui_err  kr_initMasPar( int  mode );
  35.  
  36. /* Returns the Status of the MasPar or an error code. */
  37. krui_err  kr_getMasParStatus( void );
  38. #endif
  39.  
  40. /*  Validate a network modifying operation according to the kernel mode. */
  41. krui_err  kr_validateOperation( void );
  42.  
  43. /*  Sets the topologic type of the current network.
  44.     Returns an error if the topologic type of the current network  
  45.     doesn't fit to this type.
  46.     Topologic types are:
  47.       - NET_TYPE_GENERAL
  48.         general purpose network type with no limitations
  49.       - NET_TYPE_FF1
  50.         feedforward network with fully connected units in
  51.         neighbour layers */
  52. krui_err  kr_setSpecialNetworkType( int  net_type );
  53.  
  54. /*  Returns the special topologic type of the current network, if set. */
  55. int  kr_getSpecialNetworkType( void );
  56.  
  57. /*  Creates a user defined unit. */
  58. int  kr_createUnit( char  *unit_name, char *out_func_name, char *act_func_name,
  59.            FlintTypeParam  i_act, FlintTypeParam  bias );
  60.  
  61. /*  Deletes all input links at current unit/site. */
  62. krui_err  kr_deleteAllLinks( int  mode );
  63.  
  64. /*  Deletes the current link.
  65.     NOTE: To delete a link between the current unit/site and the source unit
  66.       <source_unit_no>, call krui_isConnected( source_unit_no ) and
  67.       krui_deleteLink(). */
  68. krui_err  kr_deleteLink( void );
  69.  
  70. /*  Creates a link between source unit and the current unit/site.
  71.     Returns an error code:
  72.      - if memory allocation fails
  73.      - if source unit doesn't exist or
  74.      - if there exists already a connection between current unit/site and
  75.        the source unit
  76.     0 otherwise.
  77.     kr_createLink DO NOT set the current link.
  78.    NOTE: If you want to create a link and its unknown if there exists already a
  79.       connection between the two units, use krui_createLink and test the return
  80.       code, instead of the sequence kr_isConnected and kr_createLink. */
  81. krui_err  kr_createLink( int  source_unit_no, FlintTypeParam  weight );
  82.  
  83. /*  Sets the link weight of the current link */
  84. void  kr_setLinkWeight( FlintTypeParam    weight );
  85.  
  86. /*  Returns the link weight of the current link. */
  87. FlintType  kr_getLinkWeight( void );
  88.  
  89. /*  True if there exists a connection between source unit <source_unit_no>
  90.     and the current unit/site, otherwise false.
  91.     NOTE: If there exists a connection between the two units, the current 
  92.       link is set to the link between the two units. */
  93. bool  kr_isConnected( int  source_unit_no, FlintType   *weight );
  94.  
  95. /*  True if there exists a connection between source unit <source_unit_no>
  96.     and target unit <target_unit_no>, otherwise false. If there exist a
  97.     connection between these units, kr_areConnected returns the connection
  98.     strength also.
  99.     Returns FALSE if unit doesn't exist.
  100.     IMPORTANT: If there exist a connection, the current unit and site will be
  101.        set to the target unit/site.
  102.     NOTE: This function is slow (Units are backward chained only). */
  103. bool  kr_areConnected( int  source_unit_no, int  target_unit_no, 
  104.               FlintType   *weight );
  105.  
  106. /*  Returns the no. of first or next succecessor unit of the
  107.     given unit and the connection strenght.
  108.     Sets the current unit/site. */
  109. int  kr_getSuccessorUnit( int  mode, int  source_unit_no, FlintType  *weigth );
  110.  
  111. /*  initialize the first/next site or the named site at the current unit
  112.     for access */
  113. int  kr_setSite( int  mode, char  *site_name );
  114.  
  115. /*  initializes the given unit for access */
  116. krui_err  kr_setCurrUnit( int  unit_no );
  117.  
  118. /*  returns the number of the first/next/current unit of the unit array */
  119. int  kr_getUnit( int  mode );
  120.  
  121. /*  Returns the no. of first, next or current predecessor unit of the
  122.     current unit/site and the connection weight. */
  123. int  kr_getPredecessorUnit( int  mode, FlintType  *weight );
  124.  
  125. /*  Remove unit and all links from network. */
  126. krui_err  kr_removeUnit( struct Unit  *unit_ptr );
  127.  
  128. /*  Returns the value of the specified unit component. */
  129. FlintType   kr_getUnitValues( int  unit_no, int  component_selector );
  130.  
  131. /*  Sets the value of the specified unit component. */
  132. krui_err  kr_setUnitValues( int  unit_no, int  component_selector,
  133.                FlintTypeParam  value );
  134.  
  135. /*  Sets all unit components of the specified unit. */
  136. krui_err  kr_setAllUnitValues( int unit_no, FlintTypeParam out, 
  137.                   FlintTypeParam act,
  138.                   FlintTypeParam i_act, FlintTypeParam bias );
  139.  
  140. /*  delete all inputs at the given unit */
  141. void kr_deleteAllInputs( struct Unit  *unit_ptr );
  142.  
  143. /*  Deletes all output links at <source_unit>
  144.     NOTE: This function is slow. */
  145. void kr_deleteAllOutputLinks( struct Unit  *source_unit_ptr );
  146.  
  147. /*  search for a site at a unit */
  148. struct Site *kr_searchUnitSite( struct Unit  *unit_ptr, 
  149.                    struct SiteTable  *stbl_ptr );
  150.  
  151. /*  search for a site at a unit and returns also the predecessor site ptr */
  152. void kr_searchUnitSiteWithPred( struct Unit  *unit_ptr, 
  153.                    struct SiteTable  *stbl_ptr,
  154.                    struct Site  * *Rsite_ptr, 
  155.                    struct Site  * *Rsite_pred_ptr );
  156.  
  157. /*  searches for a site in the network  */
  158. int kr_searchNetSite( struct SiteTable  *stbl_ptr );
  159.  
  160. /*  Creates a new site with default initialisation */
  161. struct Site *kr_createDefaultSite( void );
  162.  
  163. /* returns the pointer to the given unit, returns NULL if unit doesn't exist */
  164. struct Unit *kr_getUnitPtr( int  unit_no );
  165.  
  166. /*  Searches for a unit with the given symbol pointer.
  167.     Returns the first unit no. if a unit with the given name was found,
  168.     0 otherwise.*/
  169. int kr_unitNameSearch( int  min_unit_no, char  *unit_symbol_ptr );
  170.  
  171. /*  Creates a unit with default values. */
  172. int  kr_makeDefaultUnit( void );
  173.  
  174.  
  175. /*  Copy a given unit, according to the copy mode
  176.         1. copy unit (with it sites, if available) and input/output links
  177.         2. copy unit (with it sites, if available) and input links
  178.         3. copy unit (with it sites, if available) and output links
  179.         4. copy unit (with it sites, if available) but no input/output links
  180.  
  181.     Returns the unit number of the new unit or error message < 0 , if errors 
  182.     occured. Function has no effect on the current unit.
  183.     NOTE: Copying of output links is slow.
  184.       If return code < 0, an error occured.*/
  185. krui_err  kr_copyUnit( int  copy_mode, int  source_unit );
  186.  
  187. /*  Sets the topologic type of the unit. */
  188. krui_err  kr_unitSetTType( int  unit_no, int  UnitTType );
  189.  
  190.  
  191. /*  changes all units in the network with the given functionality type
  192.     to the new functions of the (new) functionality type */
  193. void kr_changeFtypeUnits( struct  FtypeUnitStruct  *Ftype_entry );
  194.  
  195. /*   delete the functionality type of the units with the given type */
  196. void kr_deleteUnitsFtype( struct  FtypeUnitStruct  *ftype_ptr );
  197.  
  198. /*  create a new unit with the given functionality type */
  199. int  kr_makeFtypeUnit( char  *Ftype_symbol );
  200.  
  201. /*  returns TRUE, if there exists the given site at the given ftype entry */
  202. bool kr_FtypeSiteSearch( struct  Site  *ftype_first_site, 
  203.             struct  SiteTable  *site_table_ptr );
  204.  
  205. /*  change the properties of the given unit to the properties of the
  206.     given F-Type */
  207. void kr_changeFtypeUnit( struct  Unit  *unit_ptr, 
  208.             struct  FtypeUnitStruct  *ftype_ptr );
  209.  
  210. /*  change a site at the F-Type */
  211. void kr_changeFtypeSites( struct  FtypeUnitStruct  *Ftype_entry, 
  212.                           struct  SiteTable  *old_site_table,
  213.                           struct  SiteTable  *new_site_table );
  214.  
  215. /*  spell checker  (check identifiers for matching [A-Za-z]^[|, ]*) */
  216. bool kr_symbolCheck( char    *symbol );
  217.  
  218. /*  translate unit flags to the topological type of the unit */
  219. int kr_flags2TType( int  flags );
  220.  
  221. /*  translate the topological type to unit flags */
  222. int kr_TType2Flags( int  ttype );
  223.  
  224. /*  update the outputs of all units in the network */
  225. void kr_updateUnitOutputs( void );
  226.  
  227. /*  returns the no. of units of the specified topologic type
  228.     (i.e. Input, Hidden, Output or Special units) */
  229. int kr_getNoOfUnits( int  UnitTType );
  230.  
  231. /*  force unit array garbage collection */
  232. void  kr_forceUnitGC( void );
  233.  
  234.  
  235. /*#################################################
  236.  
  237. GROUP: Topological Sorting Functions
  238.  
  239. #################################################*/
  240.  
  241.  
  242. /*  Sort units according to the given mode:
  243.     TOPOLOGICAL:
  244.       Sort units topological (general version) and stores the
  245.       pointers to this units in the topologic array.
  246.       NOTE: Units are not sorted by their topologic type (that's not
  247.         possible in general case).
  248.  
  249.     TOPOLOGICAL_FF:
  250.       Sorts unit topological in feed-forward networks and stores the
  251.       pointers to this units in the topologic array in the following order:
  252.        - input,
  253.        - hidden and
  254.        - output units
  255.  
  256.       This function make following assumtions (like all learning functions for
  257.       feed-forward networks):
  258.        a) input units doesn't have input connections to other units and
  259.        b) output units doesn't have outputs connections to other units.
  260.  
  261.     TOPOLOGIC_TYPE:
  262.       Sort units by their topologic type, i.e. Input, Hidden, Output units and
  263.       stores the pointers to this units in the topologic array. */
  264. krui_err kr_topoSort( int sort_mode );
  265.  
  266.  
  267. /*  Checks the topology of the network:
  268.      a) counts the number of layers of the network and
  269.      b) determines if the network has cycles.
  270.     Returns the no. of layers of the network. */
  271. int kr_topoCheck( void );
  272.  
  273. /*  Count the no. of input and output units and return an error code
  274.     if the no. do not fit to the loaded patterns. */
  275. krui_err  kr_IOCheck( void );
  276.  
  277. krui_err  kr_makeUnitPermutation( void );
  278.  
  279.  
  280. /*#################################################
  281.  
  282. GROUP: Other functions
  283.  
  284. #################################################*/
  285.  
  286.  
  287. /*  Add random uniform distributed values to connection weights.
  288.     <minus> must be less then <plus>. */
  289. void kr_jogWeights( FlintTypeParam  minus, FlintTypeParam  plus );
  290.  
  291. /*  calls a network function */
  292. krui_err  kr_callNetworkFunction( int  type, float  *parameterInArray, 
  293.                  int  NoOfInParams, float * *parameterOutArray,
  294.                  int  *NoOfOutParams,
  295.                  int  start_pattern, int  end_pattern );
  296.  
  297. /*  Returns information about the unit default settings. */
  298. void kr_getUnitDefaults( FlintType  *act, FlintType  *bias, int     *ttflags, 
  299.             int  *subnet_no, int  *layer_no, 
  300.             char * *act_func, char * *out_func );
  301.  
  302. /*  Changes the unit default settings. */
  303. krui_err kr_setUnitDefaults( FlintTypeParam  act, FlintTypeParam  bias, 
  304.                 int  ttflags, int  subnet_no, int  layer_no, 
  305.                 char  *act_func_ptr, char  *out_func_ptr );
  306.  
  307.  
  308. /*#################################################
  309.  
  310. GROUP: Global Var's
  311.  
  312. #################################################*/
  313.  
  314. bool    NetModified = FALSE,   /* TRUE, if the network topology was modified */
  315.         NetInitialize = TRUE,  /* TRUE, if the network has been initialized  */
  316.         LearnFuncHasChanged = TRUE;  /* TRUE, if the learning func changed  */
  317.  
  318. FlagWord  DefaultSType   = DEF_STYPE;  /*  default topological type    */
  319.  
  320. int  NoOfUnits     = 0,    /*  no. of units in the network  */
  321.      MinUnitNo     = 0,    /*  the first (lowest) used unit no. in the network */
  322.      MaxUnitNo     = 0,     /*  the last (highest) used unit no. in the network */
  323.      NoOfInputUnits   = 0,    /*  no. of input units    */
  324.      NoOfOutputUnits  = 0,      /*  no. of output units  */
  325.      NoOfHiddenUnits  = 0,    /*  no. of hidden units  */
  326.      TopoSortID       = NOT_SORTED;  /*  topologic mode identifier  */
  327.  
  328. UnitArray     unit_array       = NULL;  /* the unit array  */
  329.  
  330. TopoPtrArray  topo_ptr_array   = NULL;  /* pointers to topological sorted units
  331.                        used by kr_topoSort()  */
  332.  
  333. int  no_of_topo_units = 0;  /*  no. of unit pointers in the topo_ptr_array  */
  334.  
  335.  
  336.  
  337. /*  Kernel Interface Error Code */
  338. krui_err  KernelErrorCode = KRERR_NO_ERROR;
  339.  
  340. /*  File I/O: Line number of the network file. */
  341. int  lineno = 0;
  342.  
  343. /*  Stores the error codes and messages of the
  344.     topologic sorting and network checking
  345.     functions. */
  346. struct TopologicMessages  topo_msg;
  347.  
  348.  
  349. /*  Pointers and numbers for storing the current unit, site or link.
  350.     Used by unit/site/link searching routines. */
  351. struct Unit  *unitPtr = NULL;
  352. struct Site  *sitePtr = NULL,
  353.          *prevSitePtr = NULL;
  354. struct Link  *linkPtr = NULL,
  355.          *prevLinkPtr = NULL;
  356. int  unitNo = 0;
  357.  
  358.  
  359. int   specialNetworkType = NET_TYPE_GENERAL; /* topologic type of a network  */
  360.  
  361. #ifdef MASPAR_KERNEL
  362.  
  363. /*#################################################
  364.  
  365. GROUP:  Global var's of the parallel MasPar kernel
  366.  
  367. #################################################*/
  368.  
  369. int   masParStatus = MASPAR_DISCONNECT;   /*  holds the status of the MasPar */
  370.  
  371. /* stores the topologic description of a feedforward network */
  372. struct FFnetDescriptor  descrFFnet,
  373.                         descrFFnetIO;
  374.  
  375. #endif
  376.  
  377.  
  378.  
  379. /* end global definition section */
  380.  
  381. /* begin private definition section */
  382.  
  383. /*#################################################
  384.  
  385. GROUP: Local Vars
  386.  
  387. #################################################*/
  388.  
  389. /*  topological sorting: global pointer to the topologic array
  390.     (reduces memory consumption in the recursive depth search routine) */
  391. static TopoPtrArray    global_topo_ptr;
  392.  
  393. static int  DefaultSubnetNo  = DEF_SUBNET_NO,     /*  default subnet no.  */
  394.             DefaultLayerNo   = DEF_LAYER_NO,     /*  default layer no.    */
  395.             DefaultPosX      = DEF_POS_X,     /*  default x-position  */
  396.             DefaultPosY      = DEF_POS_Y;     /*  default y-position  */
  397. #ifdef KERNEL3D
  398. static int  DefaultPosZ = DEF_POS_Z;     /*  default z-position  */
  399. #endif
  400.  
  401. static FlintType
  402.      DefaultIAct      = DEF_I_ACT,     /*  default initial activation  */
  403.      DefaultBias      = DEF_BIAS;     /*  default bias */
  404.  
  405.  
  406. static OutFuncPtr  DefaultUFuncOut  = NULL; /*  default output function     */
  407. static ActFuncPtr  DefaultUFuncAct  = NULL; /*  default activation function */
  408.  
  409. /*  default derivation act. function  */
  410. static ActDerivFuncPtr    DefaultUFuncActDeriv = NULL;
  411.  
  412. #ifdef KERNEL3D
  413.  
  414. struct TransTable  *transTable = NULL;
  415. int transTableSize = 0;
  416.  
  417. #endif
  418.  
  419.  
  420. /*#################################################
  421.  
  422. GROUP: Macros
  423.  
  424. #################################################*/
  425.  
  426.  
  427.  
  428. /*#################################################
  429.  
  430. GROUP: Functions 
  431.  
  432. #################################################*/
  433.  
  434. /* count units according to their topological type */
  435. static void  kr_countUnits(struct Unit *unit_ptr, int mode);
  436.  
  437. /*  */
  438. static int  kr_searchOutputConnection(struct Unit *start_unit_ptr, 
  439.                       struct Unit *source_unit_ptr, 
  440.                       FlintType *weight);
  441.  
  442. /* Copies all output links at <source_unit> to <new_unit>. */
  443. static krui_err  kr_copyOutputLinks(struct Unit *source_unit_ptr, 
  444.                     struct Unit *new_unit_ptr);
  445.  
  446. /* Copy all input links from <source_unit> to <new_unit> */
  447. static krui_err  kr_copyInputLinks(struct Unit *source_unit_ptr, 
  448.                    struct Unit *new_unit_ptr);
  449.  
  450. /* copy the source unit with sites, but no links */
  451. static krui_err kr_copyUnitFrame(struct Unit *source_unit_ptr, 
  452.                  struct Unit *new_unit_ptr);
  453.  
  454. /*  calls the current network function */
  455. static krui_err  kr_callNetworkFunctionSTD(int type, float *parameterInArray, 
  456.                        int NoOfInParams, 
  457.                        float **parameterOutArray, 
  458.                        int *NoOfOutParams, 
  459.                        int start_pattern, int end_pattern);
  460.  
  461.  
  462. /* end private definition section */
  463.  
  464. #endif  /* _KERNEL_DEFINED_ */
  465.